/** * 左边菜单 */
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg" src="@/assets/img/5.png" />
    </div>

    <div v-for="(item,index) in menuList" :key="item.value">
      <el-menu-item v-if="item.chilren===null" :index="item.path">
        <i class="el-icon-menu"></i>
        <span slot="title">{{item.label}}</span>
      </el-menu-item>

      <el-submenu v-else :index="index+1+''">
        <template slot="title">
          <i :class="item.icon"></i>
          <span>{{item.label}}</span>
        </template>

        <div v-for="menu in item.chilren" :key="menu.value">
          <div v-if="menu.key=='sys:menu:unit_one'">
            <el-menu-item :index="menu.path+user.unit.id">
              <i :class="menu.icon"></i>
              <span slot="title">{{user.unit.unitName}}</span>
            </el-menu-item>
          </div>

          <div v-else-if="menu.key=='sys:menu:unit_all'">
            <el-menu-item v-for="unit in unitList" :key="unit.id" :index="menu.path+unit.id">
              <i :class="menu.icon+'-'+1"></i>
              <span slot="title">{{unit.unitName}}</span>
            </el-menu-item>
          </div>

          <el-menu-item v-else :index="menu.path">
            <i :class="menu.icon"></i>
            <span slot="title">{{menu.label}}</span>
          </el-menu-item>
        </div>
      </el-submenu>
    </div>

  </el-menu>
</template>
<script>
import {
  adminUserMenuListApi,
  adminGetUserByIdApi,
  adminGetUnitListApi,
} from "@/api/admin";
export default {
  name: "leftnav",
  data() {
    return {
      collapsed: false,
      menuList: [],
      user: {},
      unitList: [],
    };
  },
  methods: {
    //获取菜单信息
    getMenuList() {
      adminUserMenuListApi().then((res) => {
        const result = res.data;
        if (result.status == 200) {
          this.menuList = result.data;
        }
      });
    },
    //获取用户信息
    getUserInfo() {
      const user = this.$store.state.localUser;
      adminGetUserByIdApi(user.id).then((res) => {
        const result = res.data;
        if (result.status == 200) {
          this.user = result.data;
        }
      });
    },
    //获取分队信息
    getUnitList() {
      adminGetUnitListApi().then((res) => {
        const result = res.data;
        if (result.status == 200) {
          this.unitList = result.data;
        }
      });
    },
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.getMenuList();
    this.getUserInfo();
    this.getUnitList();
    this.$root.Bus.$on("toggle", (value) => {
      this.collapsed = !value;
    });
  },
};
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}
.el-menu-item-group__title {
  padding: 0px;
}
.el-menu-bg {
  background-color: #1f2d3d !important;
}
.el-menu {
  border: none;
}
.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}
.logoimg {
  height: 40px;
}
</style>
